/*******************************************************************************
 * SVN­Versioning-Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­
 * $LastChangedRevision: 128 $
 * $LastChangedBy: SD $
 * $LastChangedDate: 2009-06-23 12:33:08 +0200 (Tue, 23 Jun 2009) $
 * $HeadURL: svn://lvis10.fbm.fht-stuttgart.de/common/Common/src/de/hft_stuttgart/botwar/common/commands/ShootCmd.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.common.commands;

/**
 * This command represents a shoot.
 * @author c.a.duevel@gmail.com
 */
public final class ShootCmd extends Cmd {

    private final Integer attackRobotID;
    private final Integer targetRobotID;
    private final Integer energyLeft;

    /**
     * New shoot command.
     * @param attackRobotID The ID of the attacking robot
     * @param targetRobotID The ID of the attacked robot
     */
    public ShootCmd(final Integer attackRobotID, final Integer targetRobotID) {
        this.attackRobotID = attackRobotID;
        this.targetRobotID = targetRobotID;
        this.energyLeft = 0;
    }

    /**
     * New shoot command.
     * @param attackRobotID The ID of the attacking robot
     * @param targetRobotID The ID of the attacked robot
     * @param energyLeft The amount of energy left on attacked robot
     */
    public ShootCmd(final Integer attackRobotID, final Integer targetRobotID,
            final Integer energyLeft) {

        this.attackRobotID = attackRobotID;
        this.targetRobotID = targetRobotID;
        this.energyLeft = energyLeft;
    }

    /**
     * Returns the id of attacked robot.
     * @return attackRobotID of the attacking robot
     */
    public Integer getAttackRobotId() {
        return attackRobotID;
    }

    /**
     * Returns the target robot id.
     * @return targetRobotID of the attacked robot
     */
    public Integer getTargetRobotId() {
        return targetRobotID;
    }

    /**
     * @return energyLeft of attacked robot
     */
    public Integer getTargetRobotEnergyLeft() {
        return energyLeft;
    }

    /**
     * Overrides equals().
     * @param obj object to compare
     * @return boolean true or false
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ShootCmd other = (ShootCmd) obj;
        if (this.attackRobotID != other.attackRobotID &&
                (this.attackRobotID == null ||
                !this.attackRobotID.equals(other.attackRobotID))) {

            return false;
        }
        if (this.targetRobotID != other.targetRobotID &&
                (this.targetRobotID == null ||
                !this.targetRobotID.equals(other.targetRobotID))) {

            return false;
        }
        return true;
    }

    /**
     * Overrides toString().
     * @return String getTargetRobotId() getAttackRobotId()
     */
    @Override
    public String toString() {
        return String.format("Robot %d shoots robot %d", getAttackRobotId(),
                getTargetRobotId());
    }
}
